package com.bush.mall.ware.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.springframework.util.Assert;

import com.bush.mall.common.entity.Result;
import com.bush.mall.common.exception.SaaSException;
import com.bush.mall.ware.mapper.WareOrderTaskDetailMapper;
import com.bush.mall.ware.entity.WareOrderTaskDetailEntity;
import com.bush.mall.ware.service.WareOrderTaskDetailService;

/**
 * 库存工作单
 * @author RUN
 * @date 2022-11-29
 */
@Service(WareOrderTaskDetailService.BEAN_ID)
@Slf4j
public class WareOrderTaskDetailServiceImpl extends ServiceImpl<WareOrderTaskDetailMapper, WareOrderTaskDetailEntity> implements WareOrderTaskDetailService {

    /**
     * 查询库存工作单列表
     * @author RUN
     * @date 2022-11-29
     */
    @Override
    public Result queryForPage(Integer current,Integer size) {
        try{
            Assert.notNull(current,"参数异常");
            Assert.notNull(size,"参数异常");
            Page<WareOrderTaskDetailEntity> page = new Page<>(current,size);
            QueryWrapper<WareOrderTaskDetailEntity> wrapper = new QueryWrapper<>();
            wrapper.orderByDesc("create_time");
            baseMapper.selectPage(page,wrapper);
            return Result.ok(page);
        }catch(Exception e){
            log.error("WareOrderTaskDetailService queryForPage ERROR => {}" , e.getMessage());
            return Result.error(e.getMessage());
        }
    }

    /**
     * 创建库存工作单表单对象
     * @author RUN
     * @date 2022-11-29
     */
    @Override
    public Result saveWareOrderTaskDetail(WareOrderTaskDetailEntity wareOrderTaskDetail) {
        try{
            Assert.notNull(wareOrderTaskDetail,"参数异常");
            boolean flag = this.save(wareOrderTaskDetail);
            if (flag) return Result.ok("库存工作单添加成功");
            throw new SaaSException("库存工作单添加失败");
        }catch(Exception e){
            log.error("WareOrderTaskDetailService saveWareOrderTaskDetail ERROR => {}" , e.getMessage());
            return Result.error(e.getMessage());
        }
    }


    /**
     * 修改库存工作单表单对象
     * @author RUN
     * @date 2022-11-29
     */
    @Override
    public Result updateWareOrderTaskDetail(WareOrderTaskDetailEntity wareOrderTaskDetail) {
        try{
            Assert.notNull(wareOrderTaskDetail,"参数异常");
            boolean flag = this.updateById(wareOrderTaskDetail);
            if (flag) return Result.ok("库存工作单修改成功");
            throw new SaaSException("库存工作单修改失败");
        }catch(Exception e){
            log.error("WareOrderTaskDetailService updateWareOrderTaskDetail ERROR => {}" , e.getMessage());
            return Result.error(e.getMessage());
        }
    }


    /**
     * 通过id删除库存工作单表单
     * @author RUN
     * @date 2022-11-29
     */
    @Override
    public Result deleteWareOrderTaskDetail(Long id) {
        try{
            Assert.notNull(id,"参数异常");
            boolean flag = this.removeById(id);
            if (flag) return Result.ok("库存工作单删除成功");
            throw new SaaSException("库存工作单删除失败");
        }catch(Exception e){
            log.error("WareOrderTaskDetailService deleteWareOrderTaskDetail ERROR => {}" , e.getMessage());
            return Result.error(e.getMessage());
        }
    }




}